package com.ruoyi.backups.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.backups.domain.MysqlBackups;
import com.ruoyi.backups.service.IMysqlBackupsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * mySQL数据源配置Controller
 * 
 * @author ruoyi
 * @date 2024-09-06
 */
@RestController
@RequestMapping("/backups/backups")
public class MysqlBackupsController extends BaseController
{
    @Autowired
    private IMysqlBackupsService mysqlBackupsService;

    /**
     * 查询mySQL数据源配置列表
     */
    @PreAuthorize("@ss.hasPermi('backups:backups:list')")
    @GetMapping("/list")
    public TableDataInfo list(MysqlBackups mysqlBackups)
    {
        startPage();
        List<MysqlBackups> list = mysqlBackupsService.selectMysqlBackupsList(mysqlBackups);
        return getDataTable(list);
    }

    /**
     * 查询mySQL数据源配置列表
     */
    @GetMapping("/listBySelect")
    public AjaxResult listBySelect(MysqlBackups mysqlBackups)
    {
        startPage();
        List<MysqlBackups> list = mysqlBackupsService.selectMysqlBackupsList(mysqlBackups);
        return AjaxResult.success(list);
    }

    /**
     * 导出mySQL数据源配置列表
     */
    @PreAuthorize("@ss.hasPermi('backups:backups:export')")
    @Log(title = "mySQL数据源配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MysqlBackups mysqlBackups)
    {
        List<MysqlBackups> list = mysqlBackupsService.selectMysqlBackupsList(mysqlBackups);
        ExcelUtil<MysqlBackups> util = new ExcelUtil<MysqlBackups>(MysqlBackups.class);
        util.exportExcel(response, list, "mySQL数据源配置数据");
    }

    /**
     * 获取mySQL数据源配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('backups:backups:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mysqlBackupsService.selectMysqlBackupsById(id));
    }

    /**
     * 新增mySQL数据源配置
     */
    @PreAuthorize("@ss.hasPermi('backups:backups:add')")
    @Log(title = "mySQL数据源配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MysqlBackups mysqlBackups)
    {
        return toAjax(mysqlBackupsService.insertMysqlBackups(mysqlBackups));
    }

    /**
     * 修改mySQL数据源配置
     */
    @PreAuthorize("@ss.hasPermi('backups:backups:edit')")
    @Log(title = "mySQL数据源配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MysqlBackups mysqlBackups)
    {
        return toAjax(mysqlBackupsService.updateMysqlBackups(mysqlBackups));
    }

    /**
     * 删除mySQL数据源配置
     */
    @PreAuthorize("@ss.hasPermi('backups:backups:remove')")
    @Log(title = "mySQL数据源配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mysqlBackupsService.deleteMysqlBackupsByIds(ids));
    }
}
